package com.cskaoyan.controller.system;

import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.po.MarketAdmin;
import com.cskaoyan.bean.po.MarketLog;
import com.cskaoyan.service.system.OperationLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 操作日志模块
 */
@RestController
@RequestMapping("admin/log")
public class OperationLog {

    @Autowired
    OperationLogService operationLogService;

    /**
     * 显示日志信息
     * @param page
     * @param limit
     * @param sort
     * @param order
     * @param request
     * @return
     */
    @RequestMapping("list")
    public BaseRespVo<CommonData<MarketLog>>  log(@RequestParam("page")Integer page,
                     @RequestParam("limit")Integer limit,
                     @RequestParam("sort")String sort,
                     @RequestParam("order")String order,
                     HttpServletRequest request){
  //响应：{"errno":0,"data":{"total":411,"pages":21,"limit":20,"page":1,"list":[{"id":411,"admin":"admin123","ip":"111.175.28.72","type":1,"action":"登录","status":true,"result":"","comment":"","addTime":"2022-11-20 17:06:48","updateTime":"2022-11-20 17:06:48","deleted":false},{"id":410,"admin":"admin123","ip":"183.94.140.180","type":1,"action":"添加管理员","status":true,"result":"ndcjsh","comment":"","addTime":"2022-11-20 17:06:37","updateTime":"2022-11-20 17:06:37","deleted":false},{"id":409,"admin":"admin123","ip":"36.17.123.22","type":2,"action":"发货","status":true,"result":"订单编号 20221118410157","comment":"","addTime":"2022-11-20 17:01:58","updateTime":"2022-11-20 17:01:58","deleted":false},{"id":408,"admin":"admin123","ip":"111.175.28.72","type":1,"action":"登录","status":true,"result":"","comment":"","addTime":"2022-11-20 16:59:11","updateTime":"2022-11-20 16:59:11","deleted":false},{"id":407,"admin":"admin123","ip":"183.94.140.241","type":1,"action":"登录","status":true,"result":"","comment":"","addTime":"2022-11-20 16:55:18","updateTime":"2022-11-20 16:55:18","deleted":false},{"id":406,"admin":"admin123","ip":"111.175.28.72","type":1,"action":"登录","status":true,"result":"","comment":"","addTime":"2022-11-20 16:47:50","updateTime":"2022-11-20 16:47:50","deleted":false},{"id":405,"admin":"admin123","ip":"111.175.28.72","type":1,"action":"登录","status":true,"result":"","comment":"","addTime":"2022-11-20 16:47:37","updateTime":"2022-11-20 16:47:37","deleted":false},{"id":404,"admin":"admin123","ip":"183.94.132.79","type":1,"action":"登录","status":true,"result":"","comment":"","addTime":"2022-11-20 16:47:00","updateTime":"2022-11-20 16:47:00","deleted":false},{"id":403,"admin":"admin123","ip":"111.175.28.72","type":1,"action":"删除管理员","status":true,"result":"qweqweqeqweqew","comment":"","addTime":"2022-11-20 16:45:49","updateTime":"2022-11-20 16:45:49","deleted":false},{"id":402,"admin":"admin123","ip":"111.175.28.72","type":1,"action":"登录","status":true,"result":"","comment":"","addTime":"2022-11-20 16:45:47","updateTime":"2022-11-20 16:45:47","deleted":false},{"id":401,"admin":"admin123","ip":"111.175.28.72","type":1,"action":"登录","status":true,"result":"","comment":"","addTime":"2022-11-20 16:42:24","updateTime":"2022-11-20 16:42:24","deleted":false},{"id":400,"admin":"admin123","ip":"183.94.140.229","type":1,"action":"登录","status":true,"result":"","comment":"","addTime":"2022-11-20 16:31:30","updateTime":"2022-11-20 16:31:30","deleted":false},{"id":399,"admin":"admin123","ip":"111.175.28.72","type":1,"action":"登录","status":true,"result":"","comment":"","addTime":"2022-11-20 16:28:28","updateTime":"2022-11-20 16:28:28","deleted":false},{"id":398,"admin":"admin123","ip":"183.94.140.180","type":1,"action":"登录","status":true,"result":"","comment":"","addTime":"2022-11-20 16:27:41","updateTime":"2022-11-20 16:27:41","deleted":false},{"id":397,"admin":"admin123","ip":"111.175.28.72","type":1,"action":"登录","status":true,"result":"","comment":"","addTime":"2022-11-20 16:21:32","updateTime":"2022-11-20 16:21:32","deleted":false},{"id":396,"admin":"admin123","ip":"111.175.28.72","type":1,"action":"登录","status":true,"result":"","comment":"","addTime":"2022-11-20 16:15:46","updateTime":"2022-11-20 16:15:46","deleted":false},{"id":395,"admin":"admin123","ip":"111.175.28.72","type":1,"action":"登录","status":true,"result":"","comment":"","addTime":"2022-11-20 16:11:49","updateTime":"2022-11-20 16:11:49","deleted":false},{"id":394,"admin":"admin123","ip":"111.175.28.72","type":1,"action":"登录","status":true,"result":"","comment":"","addTime":"2022-11-20 16:11:18","updateTime":"2022-11-20 16:11:18","deleted":false},{"id":393,"admin":"admin123","ip":"111.175.28.72","type":1,"action":"登录","status":true,"result":"","comment":"","addTime":"2022-11-20 16:11:07","updateTime":"2022-11-20 16:11:07","deleted":false},{"id":392,"admin":"admin123","ip":"111.175.28.72","type":1,"action":"添加管理员","status":true,"result":"qweqweqeqweqew","comment":"","addTime":"2022-11-20 16:09:24","updateTime":"2022-11-20 16:09:24","deleted":false}]},"errmsg":"成功"}
        String name = request.getParameter("name");
        CommonData<MarketLog> marketAdminCommonData = operationLogService.selectCommonData(page, limit, sort, order,name);
        BaseRespVo<CommonData<MarketLog>> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrmsg("成功");
        baseRespVo.setErrno(0);
        baseRespVo.setData(marketAdminCommonData);
        return baseRespVo;
    }
}
